package com.tian.controller;

import com.tian.config.SystemMessageTemplateLoader;
import com.tian.factory.ApplicationContextFactory;
import com.tian.message.SendEmailMessage;
import com.tian.service.SendEmailService;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RedissonClient;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * {@code @description:} TODO
 *
 * @author tianwc ????Java??????
 * ???? 1200+java????1000+??????<a href="https://woaijava.cc/">????</a>
 * {@code @date:} 2024-03-24 10:17
 * {@code @version:} 1.0
 */
@Slf4j
@Scope("prototype")
@RestController
public class TestController {
    @Resource
    RabbitTemplate userPointConfirmRabbitTemplate;
    @Resource
    SystemMessageTemplateLoader systemMessageTemplateLoader;
    @Resource
    private RedissonClient redissonClient;

    @GetMapping("/")
    public String test() {
        SendEmailService sendEmailService = ApplicationContextFactory.getBean("sendEmailSimpleMessageService", SendEmailService.class);
        SendEmailMessage sendEmailMessage = new SendEmailMessage();
        sendEmailMessage.setRecipientEmail("603060971@qq.com");
        sendEmailMessage.setTitle("田哥测试发邮件");
        sendEmailMessage.setContent("恭喜你中了1000万大奖！哈哈哈哈");
        sendEmailMessage.setType(0);
        sendEmailMessage.setReqId("2023090112345");
        ;
        log.info("sendEmailSimpleMessageService:{}", sendEmailService.sendEmail(sendEmailMessage));
        /*List<SystemMessageTemplate> systemMessageTemplates = systemMessageTemplateLoader.getTemplates();
        log.info("systemMessageTemplates:{}", JSON.toJSONString(systemMessageTemplates));*/
        /*RLock lock = redissonClient.getLock(RedisConstantPre.USER_INFO_ID_PRE + "userPointMessage.getUserId()");
        lock.lock();
        try {
            log.info("????????");
            return chargeUserMapper.selectByPrimaryKey(1L);
        } finally {
            log.info("??????");
            lock.unlock();
        }*/
        return "ok";
    }

    @GetMapping("/push")
    public String push() {
        for (int i = 1; i <= 5; i++) {
//            CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString().concat("-") + i);
//            if (i == 2) {
//                //??????????? confirmCallback
//                userPointConfirmRabbitTemplate.convertAndSend("TestDirectExchange_111", "TestDirectRouting",
//                        JSON.toJSONString(user), correlationData);
//            } else if (i == 3) {
//                //??????????? returnCallback
//                userPointConfirmRabbitTemplate.convertAndSend("TestDirectExchange", "TestDirectRouting_111",
//                        JSON.toJSONString(user), correlationData);
//            } else {
//                //????
//                userPointConfirmRabbitTemplate.convertAndSend("TestDirectExchange", "TestDirectRouting",
//                        JSON.toJSONString(user), correlationData);
//            }
        }
        return "producer push ok";
    }
}
